/**
* page.js main de aplicativo Sencha Touch.
* Aqui se declaran el modelo-vista-controlar utilizados
* en el aplicativo.
*/

if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)) {

    document.addEventListener("deviceready", onDeviceReady, false);
}
else 
{
    onDeviceReady();
}

function closeNewWindow(me) {
try {
       window.close();
    //window.history.back();
    } catch (ex) {
        alert(' page.closeNewWindow::' + ex);
    }
}
function onDeviceReady() {
    try 
    {
        if (typeof navigator._code == "undefined") {
            navigator._codeurl = {};
            navigator._codeurl.url = "";
            navigator._codeurl.name = "";
            navigator._codeurl._ext = "xxx";
            navigator._codeurl.getUrl = function () {
                return this.url;
            }
            navigator._codeurl.getExt = function () {
                return this._ext;
            }
            navigator._codeurl.setUrl = function (sLink) {
                this.url = sLink;
                this.name = this.url.substring(this.url.lastIndexOf('/') + 1);
                this._ext = this.name.substring(this.name.lastIndexOf('.') + 1);
            }
            navigator.getCodeURL = function () {
                return this._codeurl;
            }
            navigator.getCodeURL().setUrl('http://www.enovatraining.ec/');
            
        }
    
    } catch (ex) {
        alert(' page.deviceready::' + ex);
    }
}
function onPageLoad() {
    try {
       
            var dwnldImg = document.getElementById("appLoadingIndicator");
            var toolHtml = '<div class="x-container x-toolbar-dark x-toolbar x-docked-top" id="ext-toolbar-1"><div class="x-inner x-toolbar-inner x-layout-hbox" id="ext-element-75" style="-webkit-box-align: center; "><div class="x-centered" id="ext-element-79"><div class="x-title x-floating x-layout-box-item" id="ext-title-4" style="z-index: 8 !important; -webkit-box-flex: 1; "><div class="x-innerhtml " id="ext-element-78"></div></div></div>';
            toolHtml += '<div class="x-button x-iconalign-center x-button-back" id="ext-button-1"><span style="display: none; " class="x-badge"></span><a href="./"><span class="x-button-icon reply x-icon-mask" style="" id="ext-element-76"></span></a><span style="display: none; " class="x-button-label"></span></div><div id="ext-spacer-1" class="x-layout-box-item" style="-webkit-box-flex: 1; "></div><div class="x-button x-iconalign-center x-button-decline" id="ext-button-2"><span style="display: none; " class="x-badge"></span>';
            toolHtml += '<a href="#" onclick="closeNewWindow(this); return false;" ><span class="x-button-icon delete x-icon-mask" style="" id="ext-element-77"></span></a><span style="display: none; " class="x-button-label"></span></div></div></div>';
            var codeHtml = '';
            try {
                        var string_url = document.URL;
                        var url_home   = string_url.substring(string_url.lastIndexOf('?') + 1);
                       
                        if (string_url.lastIndexOf('?') != -1) {
                            navigator.getCodeURL().setUrl(url_home);
                        }
                        var string_ext = navigator.getCodeURL().getExt();
                        switch (string_ext) {
                            case "xxx": codeHtml = '<div  style = " height: 100%; width: 100%;"><br/><center>Documento no disponible</center></div><div class="x-container x-tabbar-dark x-tabbar x-docked-bottom" id="ext-tabbar-1"><div class="x-inner x-tabbar-inner x-layout-hbox" id="ext-element-7" style="-webkit-box-align: center; -webkit-box-pack: center; "></div></div>'; break;
                            case "pdf": codeHtml = '<embed width="100%" height="100%" name="plugin" src="' + navigator.getCodeURL().getUrl() + '" type="application/pdf">'; break;
                            default: codeHtml = '<iframe id="document" width="100%"  height="100%" src="' + navigator.getCodeURL().getUrl() + '" border="0"></iframe>'; break;

                        }
                        document.write(toolHtml + codeHtml);
            } catch (ex) {
                codeHtml = '<div  style = " height: 100%; width: 100%;"><br/><center>Documento no disponible</center></div><div class="x-container x-tabbar-dark x-tabbar x-docked-bottom" id="ext-tabbar-1"><div class="x-inner x-tabbar-inner x-layout-hbox" id="ext-element-7" style="-webkit-box-align: center; -webkit-box-pack: center; "></div></div>';
                document.write(toolHtml + codeHtml);
            }
            if (dwnldImg) {
                dwnldImg.style.visibility = "display";
                dwnldImg.style.display = "none";
            }

       
    } catch (ex) {
            alert(' page.onPageLoad::' + ex);
    }
}